//
//  UserController.m
//  项目
//
//  Created by 焦钟培 on 14-12-27.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ClassificationController.h"
#import "ReadingRoomViewController.h"
#import "ClassificationTableViewCell.h"

#define kBlueColor [UIColor colorWithRed:129/255.0 green: 198/255.0 blue: 221/255.0 alpha: 1.0]

@interface ClassificationController ()

@end

@implementation ClassificationController
- (void)dealloc
{
    [_picArray release];
    [_array release];
    [_button release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSArray arrayWithObjects:@"精品",@"转藏",@"社会",@"政治",@"历史",@"文化",@"财经",@"科学",@"健康",@"生活",@"美容",@"美食",@"家具",@"育儿",@"星座",@"休闲",@"情感",@"心灵",@"幽默",@"美文",@"教育",@"职场",@"电脑",@"爱车",@"旅游",@"摄影",@"艺术",@"美图",@"原创", nil];
        self.picArray = [NSArray arrayWithObjects:@"jingpin.png",@"zhuancang.png",@"shehui.png",@"zhengzhi.png",@"lishi.png",@"wenhua.png",@"caijing.png",@"kexue.png",@"jiankang.png",@"shenghuo.png",@"meirong.png",@"meishi.png",@"jiaju.png",@"yuer.png",@"xingzuo.png",@"xiuxian.png",@"qinggan.png",@"xinling.png",@"youmo.png",@"meiwen.png",@"jiaoyu.png",@"zhichang.png",@"diannao.png",@"aiche.png",@"lvyou.png",@"sheying.png",@"yishu.png",@"meitu.png",@"yuanchuang.png", nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createTable];
}
- (void)buttonAction
{
    
}
- (void)createTable
{
    UITableView * table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.alpha = 0.8;
    [self.view addSubview:table];
    [table release];
    [table registerClass:[ClassificationTableViewCell class] forCellReuseIdentifier:@"classificationCell"];
    self.button = [[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 120, 20, 30, 25)] autorelease];
    [_button setBackgroundImage:[UIImage imageNamed:@"shuangfanhui.png"] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(returnNews:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:_button] autorelease];
}
- (void)returnNews:(UIButton *)button
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"USERTONEWS" object:self];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(recoveryI) userInfo:nil repeats:NO];
}

- (void)recoveryI
{
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"classificationCell"];
    cell.label.text = [_array objectAtIndex:indexPath.row];
    cell.image.image = [UIImage imageNamed:[_picArray objectAtIndex:indexPath.row]];
    cell.image.alpha = 1.0;
    cell.rightImage.image = [UIImage imageNamed:@"qianjin.png"];
    cell.rightImage.alpha = 0.5;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *str = [_array objectAtIndex:indexPath.row];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:str,@"text", nil];
    [dic retain];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CLASSTONEWS" object:self userInfo:dic];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CLASSTOMAIN" object:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
